package com.wgts.wgts.mvp.view.activity.shopkeeper;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.control.recycleview.BaseLoadMoreAdapter;
import com.wgts.wgts.netmodle.resp.ShopKeepFansEntity;
import com.wgts.wgts.tools.MoHuGlide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

public class MyExtensionAdapter extends BaseLoadMoreAdapter<MyExtensionAdapter.MyExtensionBody> {


    private static final int HEAD_TYPE = 0x00001;
    private static final int BODY_TYPE = 0x00002;
    private static final int NOT_MORE_TYPE = 0x00003;



    private Context context;


    private List<ShopKeepFansEntity.Entity> list;

    private OnClickListener onClickListener;

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public MyExtensionAdapter(Context context, List<ShopKeepFansEntity.Entity> list) {
        super(context);
        this.context = context;

        this.list = list;
    }

    @Override
    public void onBindBodyViewHolder(@NonNull MyExtensionBody viewHolder, final int i) {
        MoHuGlide.getInstance().glideImgsFormList(viewHolder.imgUserHead, list.get(i).userImage, context);
        viewHolder.tvUserName.setText(list.get(i).userNickName);
        viewHolder.realativeNomal.setVisibility(View.GONE);
        viewHolder.tvTime.setText(list.get(i).userTime);
        switch (list.get(i).userRole) {
            case "0":
                viewHolder.imgGrade.setImageResource(R.mipmap.ic_store_member_white);
                viewHolder.tvGrade.setText("员工");
                viewHolder.itemView.setClickable(false);
                break;
            case "1":
                viewHolder.imgGrade.setImageResource(R.mipmap.ic_store_member_white);
                viewHolder.tvGrade.setText("普通用户");
                viewHolder.realativeNomal.setVisibility(View.VISIBLE);
                viewHolder.itemView.setClickable(false);
                break;
            case "2":
                viewHolder.imgGrade.setImageResource(R.mipmap.ic_store_store_white);
                viewHolder.tvGrade.setText("店主");
                break;
            case "3":
                viewHolder.imgGrade.setImageResource(R.mipmap.ic_data_manager_white);
                viewHolder.tvGrade.setText("掌柜");
                break;
            case "4":
                viewHolder.imgGrade.setImageResource(R.mipmap.ic_data_rudder_white);
                viewHolder.tvGrade.setText("分舵主");
                break;
        }


        viewHolder.realativeNomal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, UpgradeShopKeeperActivity.class);
                context.startActivity(intent);
            }
        });

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onClickListener != null){
                    onClickListener.onClick(i);
                }
            }
        });
    }

    @NonNull
    @Override
    public MyExtensionBody onCreateBodyViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new MyExtensionBody( LayoutInflater.from(context).inflate(R.layout.my_extension_body, viewGroup, false));
    }

    @Override
    public int getBodyItemCount() {
        return list.size();
    }

    @Override
    public int getBodyItemViewType(int position) {
        return 0;
    }


    public class MyExtensionBody extends RecyclerView.ViewHolder {
        @BindView(R.id.img_user_head)
        CircleImageView imgUserHead;
        @BindView(R.id.img_right)
        ImageView imgRight;
        @BindView(R.id.tv_user_name)
        TextView tvUserName;
        @BindView(R.id.img_grade)
        ImageView imgGrade;
        @BindView(R.id.tv_grade)
        TextView tvGrade;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.realative_nomal)
        RelativeLayout realativeNomal;

        View itemView;

        public MyExtensionBody(@NonNull View itemView) {
            super(itemView);
            this.itemView = itemView;
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnClickListener{
        void onClick(int i);
    }


}
